﻿#pragma once

///GPUImage特效迁移到QT+OpenGL https://juejin.cn/post/7463471433097609251
#include <QObject>
#include <QString>
#include <QOpenGLShaderProgram>

enum OpenGLEffects {
	ORIGINAL,//原始的
	GRAY,//灰度图
	BLACK_AND_WHITE,//黑白图
	PIXEL_INVERSION,//像素取反
	GAMMA,//gamma矫正
	NOSTALGIA,//怀旧
	BRIGHTNESS_EXPOSURE_CONTRAST_STURATION,//亮度、曝光、对比度、饱和度
	CTRL_L,//色阶
};

class BaseShader : public QObject
{
	Q_OBJECT

public:
	BaseShader(QObject* parent = nullptr);
	~BaseShader();

public:
	void InitShaderSource(QString& vertexSource, QString& fragmentSource);
	/// <summary>
	/// 创建Shader 并绑定
	/// </summary>
	/// <returns></returns>
	virtual bool Create(std::function<void(int vertexIn_position, int textureIn_position, GLfloat ver[8], GLfloat tex[8])> func);

	virtual void Release();


public:
	//shader中yuv变量地址
	GLuint unis[3] = { 0 };
	QOpenGLShaderProgram program;
private:
	int vertexIn_position = 0;
	int textureIn_position = 1;

	QString vertexSource;
	QString fragmentSource;

	//顶点
	GLfloat ver[8] = {
	  -1.0f,-1.0f,
	  1.0f,-1.0f,
	  -1.0f, 1.0f,
	  1.0f,1.0f
	};

	//材质
	GLfloat tex[8] = {
	  0.0f, 1.0f,
	  1.0f, 1.0f,
	  0.0f, 0.0f,
	  1.0f, 0.0f
	};
};
